//
//  CreditCardBillViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/24.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class CreditCardBillViewController: BillRootViewController {
    
    fileprivate var model : BillModel?
    
    init(model:BillModel) {
        super.init(nibName: nil, bundle: nil)
        
        self.model = model
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(selectCardService(sender:)), name: .contactTheBank, object: nil)
        
        self.title = billDetails
        addSubView()
    }
    
    //MARK: 选择信用卡服务
    @objc fileprivate func selectCardService(sender:Notification) {
        
        if let index = sender.userInfo!["index"] as? String {
            
            switch index {
            case "0":
            self.navigationController?.pushViewController(CardViewController(), animated: true)
            case "1":
            self.navigationController?.pushViewController(BankLocationsViewController.init(bankName: ((self.model as? InputBillModel)?.bank)!), animated: true)
            case "2":
            self.navigationController?.pushViewController(ContactBankViewController.init(bankName: ((self.model as? InputBillModel)?.bank)!), animated: true)
            default:
                break
            }
        }
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self, name: .contactTheBank, object: nil)
    }
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
        let headView = CreditCardBillHeadView.init(model: self.model as! InputBillModel)
        self.view.addSubview(headView)
        
        headView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 300)+4)
        }
        
        let billServiceVC = BillServiceViewController()
        self.addChildViewController(billServiceVC)
        self.didMove(toParentViewController: billServiceVC)
        
        self.view.addSubview(billServiceVC.view)
        
        billServiceVC.view.snp.makeConstraints { (make) in
            make.top.equalTo(headView.snp.bottom).offset(1)
            make.left.right.bottom.equalToSuperview()
        }
    }


}
